﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:s="clr-namespace:IntegrationTool.DiagramDesigner"
                    xmlns:c="clr-namespace:IntegrationTool.DiagramDesigner.Controls">

    <ContextMenu x:Key="DesignerItemContextMenu">
        <MenuItem Header="Cut" Command="{x:Static ApplicationCommands.Cut}">
            <MenuItem.Icon>
                <Image Source="Images/Cut.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Copy" Command="{x:Static ApplicationCommands.Copy}">
            <MenuItem.Icon>
                <Image Source="Images/Copy.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Paste" Command="{x:Static ApplicationCommands.Paste}">
            <MenuItem.Icon>
                <Image Source="Images/Paste.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Delete" Command="{x:Static ApplicationCommands.Delete}">
            <MenuItem.Icon>
                <Image Source="Images/Delete.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="Grouping">
            <MenuItem Header="Group" Command="{x:Static s:DesignerCanvas.Group}">
                <MenuItem.Icon>
                    <Image Source="Images/Group.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Ungroup" Command="{x:Static s:DesignerCanvas.Ungroup}">
                <MenuItem.Icon>
                    <Image Source="Images/Ungroup.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="Order">
            <MenuItem Header="Bring Forward" Command="{x:Static s:DesignerCanvas.BringForward}">
                <MenuItem.Icon>
                    <Image Source="Images/BringForward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Bring To Front" Command="{x:Static s:DesignerCanvas.BringToFront}">
                <MenuItem.Icon>
                    <Image Source="Images/BringToFront.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send Backward" Command="{x:Static s:DesignerCanvas.SendBackward}">
                <MenuItem.Icon>
                    <Image Source="Images/SendBackward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send To Back" Command="{x:Static s:DesignerCanvas.SendToBack}">
                <MenuItem.Icon>
                    <Image Source="Images/SendToBack.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
    </ContextMenu>

    <!-- Connector Style -->
    <Style x:Key="DefaultConnectorStyle" TargetType="{x:Type s:Connector}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Height" Value="8"/>
        <Setter Property="Cursor" Value="Cross"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type s:Connector}">
                    <Grid>
                        <!-- transparent extra space makes connector easier to hit -->
                        <Rectangle Fill="Transparent" Margin="-2"/>
                        <Rectangle Fill="Lavender" StrokeThickness="1" Stroke="#AA000080"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Connector Error Style -->
    <Style x:Key="ErrorConnectorStyle" TargetType="{x:Type s:Connector}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Height" Value="8"/>
        <Setter Property="Cursor" Value="Cross"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type s:Connector}">
                    <Grid>
                        <!-- transparent extra space makes connector easier to hit -->
                        <Rectangle Fill="Transparent" Margin="-2"/>
                        <Rectangle Fill="Red" StrokeThickness="1" Stroke="#AA000080"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- ConnectorDecoratorTemplate Default Template -->
    <ControlTemplate x:Key="ConnectorDecoratorTemplate" TargetType="{x:Type Control}">
        <Grid Margin="-5">
            <s:Connector x:Name="Left" Type="Default" Style="{DynamicResource DefaultConnectorStyle}" Orientation="Left" VerticalAlignment="Center" HorizontalAlignment="Left"/>
            <s:Connector x:Name="Top" Type="Default" Style="{DynamicResource DefaultConnectorStyle}" Orientation="Top" VerticalAlignment="Top" HorizontalAlignment="Center"/>
            <s:Connector x:Name="Right" Type="Default" Style="{DynamicResource DefaultConnectorStyle}" Orientation="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
            <s:Connector x:Name="Bottom" Type="Default" Style="{DynamicResource DefaultConnectorStyle}" Orientation="Bottom" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
            <s:Connector x:Name="Error" Type="Error" Style="{DynamicResource ErrorConnectorStyle}" Margin="0 0 24 0" Orientation="Bottom" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
        </Grid>
    </ControlTemplate>

    <!-- ResizeDecorator Default Template -->
    <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
        <Grid Opacity="0.7" SnapsToDevicePixels="true">
            <c:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
            <c:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
            <c:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
                     VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
            <c:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
                     VerticalAlignment="Top" HorizontalAlignment="Right"/>
            <c:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
                     VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
                     VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
        </Grid>
    </ControlTemplate>

    <!-- DragThumb Default Template -->
    <Style TargetType="{x:Type c:DragThumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type c:DragThumb}">
                    <Rectangle Fill="Transparent"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DesignerItem Style -->
    <Style TargetType="{x:Type s:DesignerItem}">
        <Setter Property="MinWidth" Value="10"/>
        <Setter Property="MinHeight" Value="10"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type s:DesignerItem}">
                    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                          ContextMenu="{StaticResource DesignerItemContextMenu}">
                        
                        
                        <!-- PART_ResizeDecorator -->
                        <Control x:Name="PART_ResizeDecorator" 
                                 Visibility="Collapsed"
                                 Template="{StaticResource ResizeDecoratorTemplate}"/>
                        <!-- PART_ContentPresenter -->
                        <ContentPresenter x:Name="PART_ContentPresenter"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Content="{TemplateBinding ContentControl.Content}"
                                          Margin="{TemplateBinding ContentControl.Padding}"/>
                        <TextBox x:Name="itemEditLabelTextbox" Text="{Binding Path=ItemLabel, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource TemplatedParent}}" Margin="5 0 5 0" VerticalAlignment="Center" />
                        <Label x:Name="itemLabel" FontSize="14" FontFamily="Segoe UI Light" Foreground="White" Content="{Binding Path=ItemLabel, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        <ContentControl x:Name="itemImage" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 -12 0 0" Height="24" Width="24" Content="{Binding Path=ItemImage, RelativeSource={RelativeSource TemplatedParent}}" />
                        <!-- PART_DragThumb -->
                        <c:DragThumb x:Name="PART_DragThumb" 
                                     Cursor="SizeAll"/>
                        <!-- PART_ConnectorDecorator -->
                        <Control x:Name="PART_ConnectorDecorator"
                                 Visibility="Hidden"
                                 Template="{StaticResource ConnectorDecoratorTemplate}"/>                        
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsGroup}">
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Value="False" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsLabelInEditMode}">
                            <Setter TargetName="itemEditLabelTextbox" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="itemLabel" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsLabelInEditMode}">
                            <Setter TargetName="itemEditLabelTextbox" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="itemLabel" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}"/>
                                <Condition Value="{x:Static sys:Guid.Empty}" Binding="{Binding RelativeSource={RelativeSource Self},Path=ParentID}"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsDragConnectionOver}">
                            <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsGroup}">
                            <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>